package hbase;

import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;

import java.io.IOException;

public class HBaseUtil {
    private static HBaseConfig HBASECONFIG = new HBaseConfig();
    private static ReadHBaseConf READHBASECONFIG = new ReadHBaseConf();

    public static ReadHBaseConf getREADHBASECONFIG(){ return READHBASECONFIG; }
    public static  HBaseConfig getHBASECONFIG() { return HBASECONFIG; }

    public static void createTable(String tableName,  Connection conn){
        try {
            Admin admin = conn.getAdmin();
            if(admin.tableExists(TableName.valueOf(tableName))){
                System.out.println("该表已存在");
                return;
            }

            HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
            HColumnDescriptor hColumnDescriptor = new HColumnDescriptor("info");
            hTableDescriptor.addFamily(hColumnDescriptor);
            admin.createTable(hTableDescriptor);

        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("llll获取ADMIN失败");
        }
    }


}
